feat: allow overriding headers per request#617
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughAdds per-request custom header support to the Go SDK: introduces RequestOptions with Headers, threads options through generated API request builders and client option structs, adjusts default header application to avoid overwriting existing headers, updates docs and example, and adds comprehensive tests for header merging and precedence. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant App as Application
participant Client as Go Client (high-level)
participant SDK as Generated API Request
participant Core as prepareRequest
participant HTTP as HTTP Server
App->>Client: Invoke Method(opts with RequestOptions.Headers)
Client->>SDK: Build Api{{operation}}Request\n.Options(requestOptions).Body(...).Execute()
SDK->>Core: prepareRequest(ctx, method, path, headers, body)
Note over Core: 1) Start with local headers<br/>2) Apply per-request Headers<br/>3) Apply DefaultHeaders only if absent
Core->>HTTP: HTTP request with merged headers
HTTP-->>Core: Response
Core-->>SDK: Response
SDK-->>Client: Parsed result
Client-->>App: Return result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
config/clients/go/template/api_headers_test.go (1)
261-287: Return a BatchCheckResponse-shaped body for accuracyThe mock returns {"test-correlation-id": {...}}. The API response is {"result": {...}}. Returning the documented shape reduces future fragility.
Apply:
- server := createAPITestServer(t, &capturedHeaders, `{"test-correlation-id": {"allowed": true}}`) + server := createAPITestServer(t, &capturedHeaders, `{"result": {"test-correlation-id": {"allowed": true}}}`)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
config/clients/go/CHANGELOG.md.mustache(1 hunks)config/clients/go/config.overrides.json(1 hunks)config/clients/go/template/README_initializing.mustache(1 hunks)config/clients/go/template/api.mustache(4 hunks)config/clients/go/template/api_client.mustache(1 hunks)config/clients/go/template/api_headers_test.go(1 hunks)config/clients/go/template/client/client.mustache(48 hunks)config/clients/go/template/client/client_headers_test.go(1 hunks)config/clients/go/template/example/example1/example1.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
config/**/*.mustache
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Validate mustache syntax and variable references across all template files, including CHANGELOG.md.mustache
Files:
config/clients/go/template/api.mustacheconfig/clients/go/template/api_client.mustacheconfig/clients/go/template/README_initializing.mustacheconfig/clients/go/CHANGELOG.md.mustacheconfig/clients/go/template/client/client.mustache
config/**/*.{json,mustache}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Never hardcode API keys or credentials in configuration or template files
Files:
config/clients/go/template/api.mustacheconfig/clients/go/config.overrides.jsonconfig/clients/go/template/api_client.mustacheconfig/clients/go/template/README_initializing.mustacheconfig/clients/go/CHANGELOG.md.mustacheconfig/clients/go/template/client/client.mustache
config/clients/*/config.overrides.json
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
config/clients/*/config.overrides.json: Always update the packageVersion in each language-specific config.overrides.json when making version changes
Maintain FOSSA compliance notice IDs in each language’s config.overrides.json
Files:
config/clients/go/config.overrides.json
config/{common/config.base.json,clients/*/config.overrides.json}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Ensure consistent versioning across base and language override configuration files to avoid version conflicts
Files:
config/clients/go/config.overrides.json
🔇 Additional comments (8)
config/clients/go/CHANGELOG.md.mustache (1)
5-5: Changelog entry captures the feature wellNice to see the per-request headers support called out so it’s easy to surface in release notes.
config/clients/go/config.overrides.json (1)
48-53: Thank you for wiring the new tests into the generatorAdding these file mappings guarantees the header-focused test suites land in the generated SDK.
config/clients/go/template/api.mustache (2)
27-80: RequestOptions integration looks solidDefining the reusable RequestOptions type and threading it through the request struct plus fluent setter keeps the API ergonomic while enabling per-call header overrides.
333-336: Great call on merging override headers right before dispatchApplying the per-request headers here guarantees they take precedence without disturbing earlier header assembly logic.
config/clients/go/template/README_initializing.mustache (1)
118-155: Docs clearly explain both default and per-request header flowsThe examples make it straightforward for users to adopt the new Options-based overrides right away.
config/clients/go/template/api_client.mustache (1)
292-295: Thanks for preserving caller-specified headersGuarding the default header assignment prevents client defaults from clobbering explicit per-request values—exactly what the new feature needs.
config/clients/go/template/example/example1/example1.go (1)
257-274: Good example usage of per-request headersThe Check example with Options(RequestOptions{Headers: ...}) is correct and aligns with the new API.
config/clients/go/template/client/client.mustache (1)
683-701: RequestOptions propagation looks solidPassing request-scoped options via .Options(requestOptions) across client methods is consistent and correct.
Also applies to: 760-779, 839-857, 919-953, 1025-1045, 1140-1153, 1216-1241, 1320-1358, 1438-1474, 1668-1673, 2174-2183, 2198-2204, 2376-2380, 2560-2586, 2679-2716, 2980-2990, 3075-3083, 3216-3225
Description
This PR adds support for sending custom headers per request.
It is complete, however it's kept in draft as it will have many conflicts with the other Go SDK PRs that will need to be resolved once the others are merged.
Merge after #616
What problem is being solved?
How is it being solved?
What changes are made to solve it?
References
addresses go sdk part of #569
Review Checklist
mainSummary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests
Chores